//
//  ChannelRankListTableViewCell.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/13.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "ChannelRankListTableViewCell.h"
#import "ChannelPresentationCellFrameViewModel.h"
#import "ChannelPostModel.h"
#import "ChannelPostContent.h"
#import "ChannelPostRanklist.h"
#import "DetailLikedHeaderCollectionViewCell.h"
#import "TAMacro.h"
@interface ChannelRankListTableViewCell ()
<
    UICollectionViewDelegate,
    UICollectionViewDataSource,
    UICollectionViewDelegateFlowLayout
>

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, strong) UICollectionView *headerImageCollectionView;
@property (nonatomic, weak) UIImageView *moreImage;
@property (nonatomic, weak) UIView *backView;

@end


@implementation ChannelRankListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 所有子控件的创建
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.917 alpha:1];
        [self setUpAllChildrenView];
        
    }
    return self;
}
// 所有子控件的创建
- (void)setUpAllChildrenView {
    
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:backView];
    _backView = backView;
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.backgroundColor = [UIColor whiteColor];
    titleLabel.font = TitleFont;
    [_backView addSubview:titleLabel];
    _titleLabel = titleLabel;
    
    // 头像
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
     _headerImageCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _headerImageCollectionView.backgroundColor = [UIColor yellowColor];

    [_backView addSubview:_headerImageCollectionView];
    _headerImageCollectionView.dataSource = self;
    _headerImageCollectionView.delegate = self;
    [_headerImageCollectionView registerNib:[UINib nibWithNibName:@"DetailLikedHeaderCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"DetailLikedHeaderCollectionViewCellReuse"];
    
    // 更多
    UIImageView *moreImage = [[UIImageView alloc] init];
//    moreImage.backgroundColor = [UIColor greenColor];
    [_backView addSubview:moreImage];
    _moreImage = moreImage;
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(40, 40);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (_channelPresentationCellFrameViewModel.channelPost.content.rankList.count < 3) {
        return 0;
    }
    
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    DetailLikedHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailLikedHeaderCollectionViewCellReuse" forIndexPath:indexPath];
     cell.likeAvter = _channelPresentationCellFrameViewModel.channelPost.content.rankList[indexPath.row];
    return cell;
}


- (void)setChannelPresentationCellFrameViewModel:(ChannelPresentationCellFrameViewModel *)channelPresentationCellFrameViewModel {
    _channelPresentationCellFrameViewModel = channelPresentationCellFrameViewModel;
    // 控件赋值
    [self setUpData];
    // 控件frame
    [self setUpFrame];
}

// 控件赋值
- (void)setUpData {

//    _titleLabel.text = _channelPresentationCellFrameViewModel.channelPost.content.r
    
    _moreImage.image = [UIImage imageNamed:@"postMore"];
    _titleLabel.text = @"精选排行榜";
    
}

// 控件frame
- (void)setUpFrame {
    _backView.frame = _channelPresentationCellFrameViewModel.backViewFrame;
    _titleLabel.frame = _channelPresentationCellFrameViewModel.titleLabelFrame;
    _moreImage.frame = _channelPresentationCellFrameViewModel.moreImageFrame;
    _headerImageCollectionView.frame = _channelPresentationCellFrameViewModel.headerImageCollectionViewFrame;
}



- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
